//
//  SevenTransitionDetailViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/9.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class SevenTransitionDetailViewController: UIViewController {

    var _bgView:UIView?;
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "反面"
        self.view.backgroundColor = .clear;
        self.navigationController?.delegate = self
        // Do any additional setup after loading the view.
        self.onCreateUIForView();
    }
    

    //TODO:UI
    fileprivate func onCreateUIForView() {
        _bgView = UIView(frame: CGRect(x: 40, y: (screenMainSize.height-460)/2, width: screenMainSize.width-80, height: 460));
        _bgView?.backgroundColor = UIColor(red: CGFloat(arc4random()%255)/255.0, green: CGFloat(arc4random()%255)/255.0, blue: CGFloat(arc4random()%255)/255.0, alpha: 1.0);
        _bgView?.alpha = 0;
        self.view.addSubview(_bgView!);
    }

    //MARK:动画
    public func onShowAnimation() {
        let backgroundAnimation = CABasicAnimation(keyPath: "backgroundColor");
        backgroundAnimation.duration = 1;
        backgroundAnimation.fillMode = .forwards;
        backgroundAnimation.isRemovedOnCompletion = false;
        backgroundAnimation.beginTime = CACurrentMediaTime();
        backgroundAnimation.toValue = UIColor.lightGray.withAlphaComponent(0.75).cgColor;
        self.view.layer.add(backgroundAnimation, forKey: "background_animation");
    }
}

extension SevenTransitionDetailViewController:UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        if operation == .pop {
            return SevenTransition.transitionWithTransitionType(type: SevenTransitionType.SevenTransitionType_Pop);
        }
        return nil;
    }
}
